<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    *{
        margin: 0;
        padding: 0;
    }
    div{
        width: 500px;
        margin: 50px auto;
    }
    textarea{
        width: 400px;
        height: 300px;
        resize: none;
        outline: none;
    }
    li{
        background-color: #ccc;
        margin: 5px;
        width: 420px;
        padding: 5px 10px;
    }
    a{
        float: right;
    }
</style>
</head>
<body>
    <textarea name="" id=""></textarea>
    <button>发布</button>
    <ul></ul>
    <script>
    var btn=document.querySelector('button');
    var text=document.querySelector('textarea');
    var ul=document.querySelector('ul');
    btn.onclick=function(){
        if(text.value==''){
            alert('你没有输入内容');
            return false;
        }else{
            var li=document.createElement('li');
            li.innerHTML=text.value+'<a href="javascript:;">删除</a>';
            ul.insertBefore(li,ul.children[0]);
            var as=document.querySelectorAll('a');
            for(var i=0;i<as.length;i++){
                as[i].onclick=function(){
                    ul.removeChild(this.parentNode);
                };
            }
        }
    };
    </script>
</body>
</html>